package com.itany.corejava.day04;

import java.util.Arrays;

/*
    动态数组

    java中没有动态数组
    实际动态数组相当于数组的拷贝
    扩展的是
    改变变量的引用
 */
public class Test10 {

    public static void main(String[] args) {


        char[] c={'a','b'};

        System.out.println("c.length = " + c.length);//2

        System.out.println("c = " + Arrays.toString(c));//[a,b]

//        System.out.println(c[2]);




        c=extend(c);




        c[2]='c';

        System.out.println("c.length = " + c.length);//3

        System.out.println("c = " + Arrays.toString(c));//[a,b,c]



        c=extend(c);




        c[3]='d';

        System.out.println("c.length = " + c.length);

        System.out.println("c = " + Arrays.toString(c));


    }

    public static char[] extend(char[] arr){

        char[] temp=new char[arr.length+1];

//        for (int i = 0; i < c.length; i++) {
//            temp[i]=c[i];
//        }
        System.arraycopy(arr,0,temp,0,arr.length);

        return temp;
    }

















}
